package no.ciber.kartdemo.domain;

import com.google.code.facebookapi.schema.User;

public class GmlUtil {

	private final static String tab = "\t";
	private final static String newline = "\n";

	public static String featureCollectionStart() {
		return "<wfs:FeatureCollection xmlns:ms=\"http://mapserver.gis.umn.edu/mapserver\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd http://mapserver.gis.umn.edu/mapserver http://aneto.oco/cgi-bin/worldwfs?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=point&amp;OUTPUTFORMAT=XMLSCHEMA\">"
				+ newline;
	}

	public static String featureCollectionEnd() {
		return "</wfs:FeatureCollection>";
	}

	public static String featureMember(User user, int index) {
		return "<gml:featureMember>" + newline + person(user, index) + newline + "</gml:featureMember>" + newline;
	}

	private static String person(User user, int index) {
		return tab + "<ms:person fid=\"" + index + "\">" + newline + msGeometry(user) + newline + name(user) + newline + gender(user) + newline
				+ picture(user) + newline + relationshipStatus(user) + newline +id(user) + newline + tab + "</ms:person>";
	}

	private static String id(User user) {
		return tab + tab + "<ms:id>" + user.getUid() + "</ms:id>";
	}

	private static String gender(User user) {
		return tab + tab + "<ms:gender>" + user.getSex() + "</ms:gender>";
	}

	private static String picture(User user) {
		return tab + tab + "<ms:picture>" + user.getPicSmall() + "</ms:picture>";
	}

	private static String name(User user) {
		return tab + tab + "<ms:name>" + user.getFirstName() + " " + user.getLastName() + "</ms:name>";
	}

	private static String msGeometry(User user) {
		return tab + tab + "<ms:msGeometry>" + newline + point(user) + newline + tab + tab + "</ms:msGeometry>";
	}

	private static String relationshipStatus(User user) {
		return tab + tab + "<ms:relationshipStatus>" + user.getRelationshipStatus() + "</ms:relationshipStatus>";
	}

	private static String point(User user) {
		return tab + tab + tab + "<gml:Point>" + newline + coordinates(user) + newline + tab + tab + tab + "</gml:Point>";
	}

	private static String coordinates(User user) {
		return tab + tab + tab + tab + "<gml:coordinates>" + user.getCurrentLocation().getLongitude() + "," + user.getCurrentLocation().getLatitude()
				+ "</gml:coordinates>";
	}

}
